<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<div class="pro_list fr"  >
   <div class="title"  >
   	 <span class="titletxt">您现在的位置：</span>
     <ul> 
       <li class="root">会员中心</li>        
       <li>订单管理</li>  
       <li>我的收藏</li>            
     </ul>
   </div>
  <c:if test="${not empty ret }">
   	<c:if test="${ret.code ne '200'}">
   		<script type="text/javascript">alertError('${ret.result}');</script>
   		<div id=messager class="messager" >
	         <div class="contentmsg">
	             <h5>提示信息～！</h5>
	             <ul>
	               <li>${ret.result}</li>
	             </ul>
	        </div>
	     <div class="closer" onClick="showHideLayer('messager');" title="关闭"></div>
	    </div>
   	</c:if>
   </c:if>
<br/>
<div  class="easyui-panel" title="我的收藏"  style="">

<div data-options="region:'north',title:'',split:true" style="height:40px;background-color:#e4e4e4;">
    	<form action="" id="searchForm" name="searchForm">
    	<table>
    		<tr>
				<td class="screen-n"><span>对象名称</span></td>
				<td class="screen-n">
					<input type="text" id="objectName" class="screen-input" onkeydown="pms.kd13('initProducts')">
				</td>
				<td class="screen-n">
					<input type="button" class="button" value="查询" onclick="initProducts()">
					<input type="button" class="button" value="重置" onclick="pms.resetForm('searchForm')" >
				</td>
			</tr>
			</table>
		</form>
    </div>
    
    <div data-options="region:'center',split:true" style="width: 100%;height:431px">
		<table id="tableGrid" ></table>
	</div>
	
</div>
</div>
<script>
var productsTable;
$(function(){
	initProducts();
});

function initProducts(){
	productsTable = $('#tableGrid').pDataGrid({
		 columns:[[
	          	  {field:'favoritesId',title:'id',align:'center',sortable:true},
	          	  {field:'objectName',title:'收藏',align:'center',sortable:true},
	          	  {field:'notes',title:'备注',align:'center',sortable:true},
	          	  {field:'url',title:'超链接',align:'center',sortable:true,
	          		formatter:function(value,row){  
	                      return '<a href="' + value + '" >查看产品详情</a>';
	                      } 
	          	  },
	          	
	          	  {field:'createDate',title:'收藏时间',align:'center',sortable:true, formatter:function(value,row,index){  
                      var unixTimestamp = new Date(value);  
                      return unixTimestamp.toLocaleString();  
                      } 
	          	  }, 
	              {field:'action',title:'操作',align:'center',sortable:true,formatter:function(value,row){
		              var str = '';
/* 		              if(row.type=='product'){
		            	str+='<a href="javascript:addShoppingCart(\''+row.objectId+'\');" class="easyui-linkbutton" iconCls="icon-cancel"  >加入购物车</a>&nbsp;';
			          } */
						str+= '<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="canlOrder('+row.favoritesId+')">删除</a>';
					  return str;
		           }}
		          ]],
		    url:'<c:url value="/trade/searchPageUserProductFavorites.s"/>',  
		    pagination:true,
		    pageSize:30,
		    queryParams:{
		    	"objectName":$("#objectName").val()
		    }, 
			completeCallback:function(data){
				if(data.code == "100"){
					layer.msg(data.result);
				} 
			}
	}); 
}


function canlOrder(orderCode){
	layer.confirm('确认删除收藏？',function(index){
		var param = {"favoritesId":orderCode};
		console.log(param);
		$.pmsAjax({
			url:"<c:url value='/trade/deleteUserFavorites.s'/>",
			data:param,
			success:function(data){
				if(data.code=="200"){
					layer.msg("删除收藏成功",1, {type: 1,shade: [0.2, '#ccc']});
					productsTable.refresh();
				}else{
					 layer.msg(data.result,3, {type: 3,shade: [0.2, '#ccc']});
				}
			}
		});
	});
}
function addShoppingCart(code){
	var param = {"productCode":code,"amount":1};
	$.pmsAjax({
		url:'<c:url value="/shoppingCart/ajaxAddShoppingCart.s"/>',
		data:param,
		success:function(data){
			if(data.code=="200"){
				layer.msg("加入购物车成功",1, {type: 1,shade: [0.2, '#ccc']});
				productsTable.refresh();
			}else{
				 layer.msg(data.result,1, {type: 3,shade: [0.2, '#ccc']});
			}
		}
	});
}
</script>